package com.gujiangbo.application.utils;

import java.util.Random;
import java.util.UUID;

public class IDTools {

	public static String getRandom32() {

		return UUID.randomUUID().toString().replaceAll("-", "").trim();
	}

	public static String getRandom15() {
		return getRandomString(15);
	}

	/**
	 * 生成指定位数的随机数
	 *
	 * @param length
	 * @return
	 */
	private static String getRandomString(int length) { // length表示生成字符串的长度
		String base = "abcdefghijklmnopqrstuvwxyz0123456789";
		Random random = new Random();
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < length; i++) {
			int number = random.nextInt(base.length());
			sb.append(base.charAt(number));
		}
		return sb.toString().toUpperCase();
	}

	public static String getID() {
		return DateTool.get17CurrentTime() + getRandom4();
	}

	public static String getRandom4() {
		String num = "";
		String[] src = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
		Random r = new Random();
		for (int i = 0; i < 4; i++) {
			num = num + src[r.nextInt(src.length)];
		}
		return num;
	}

	public static String getRandom6() {
		String num = "";
		String[] src = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
				"t", "u", "v", "w", "x", "y", "z" };
		Random r = new Random();
		for (int i = 0; i < 6; i++) {
			num = num + src[r.nextInt(src.length)];
		}
		return num;
	}

	public static String getGlobalSessionID(String config) {
		Random random = new Random();
		int min = 100000;
		int max = 999999;
		int rNum = random.nextInt(max) % (max - min + 1) + min;
		return DateTool.getCurrentTime() + config + String.valueOf(rNum);
	}

	public static void main(String[] args) {
		System.out.println(getRandom32());
		System.out.println(getRandom6());
		System.out.println(getGlobalSessionID(""));
	}
}
